package controller.res;

import model.MResource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import common.interf.IErrorHandle;

import service.interf.IResource;

@Controller
@RequestMapping("/res")
public class ResourceEditController {
	@Autowired
	private IResource res;
	
	private IErrorHandle errorHandle;
	
	public void setErrorHandle(IErrorHandle errorHandle) {
		this.errorHandle = errorHandle;
	}

	/*
	 * 添加资源
	 */
	@RequestMapping("/add_resource.htm")
	@ResponseBody
	public String add(MResource model){
		String x = "";
		try{
			x = res.addResource(model);
		} catch (Exception e){
			x = errorHandle.handleErr(e);
		}
		return x;
	}
	
	/*
	 * 编辑资源
	 */
	@RequestMapping("/edit_resource.htm")
	@ResponseBody
	public String edit(MResource model){
		String x;
		try{
			x = res.editResource(model);
		}catch(Exception e){
			x = errorHandle.handleErr(e);
		}
		return x;
	}
	
	/*
	 * 删除资源
	 */
	@RequestMapping("del_resource.htm")
	public String del(MResource model){
		String x;
		try{
			x = res.delResource(model);
		}catch(Exception e){
			x = errorHandle.handleErr(e);
		}
		return x;
	}
	
	/*
	 * 批量保存
	 */
	@RequestMapping("/batch_saveResource.htm")
	public String batch(MResource model){
		String x="";
		try{
			x = res.batchUpdate(model.getDatas());
		}catch(Exception e){
			x = errorHandle.handleErr(e);
		}
		return x;
	}
	
	
}
